//
//  MyPointsTableHeader.m
//  BaseProject
//
//  Created by 王盼盼 on 2024/11/7.
//  Copyright © 2024 wangpanpan. All rights reserved.
//

#import "MyPointsTableHeader.h"

@interface MyPointsTableHeader ()
@property(nonatomic, strong) NSArray<UIView *> *items;
@end

@implementation MyPointsTableHeader
- (void)makeUI {
    [super makeUI];
    self.backgroundColor = rgba(255, 245, 236, 1);
}
- (void)setType:(NSInteger)type {
    _type = type;
    [self.items enumerateObjectsUsingBlock:^(UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
    }];
    self.items = @[];
    
    NSArray *titles;
    NSArray<NSNumber *> *orinXs;
    NSArray<NSNumber *> *itemWidths;
    if (type == 1) {
        titles = @[@"商家", @"创建时间", @"补贴金额"];
        orinXs = @[@(16.0), @(self.width * 0.3), @(self.width * 0.75)];
        itemWidths = @[@(self.width * 0.3 - 30), @(self.width * 0.45 - 5), @(self.width * 0.25 - 5)];
    } else if (type == 2) {
        titles = @[@"用户名", @"推荐时间", @"消费总金额"];
        orinXs = @[@(16.0), @(self.width * 0.3), @(self.width * 0.7)];
        itemWidths = @[@(self.width * 0.3 - 20), @(self.width * 0.4 - 5), @(self.width * 0.3 - 5)];
    } else {
        titles = @[@"订单号", @"创建时间", @"积分"];
        orinXs = @[@(16.0), @(self.width * 0.4), @(self.width * 0.8)];
        itemWidths = @[@(self.width * 0.4 - 20), @(self.width * 0.4 - 5), @(self.width * 0.2 - 5)];
    }
    NSMutableArray *items = [NSMutableArray array];
    for (NSInteger index = 0; index < titles.count; index ++) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(orinXs[index].doubleValue, 0, itemWidths[index].doubleValue, self.height)];
        [self addSubview:label];
        label.text = titles[index];
        label.font = kFontRegular(14);
        label.textColor = rgba(137, 137, 145, 1);
        [items addObject:label];
    }
    self.items = items;
}
@end
